#define  _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <stdlib.h>

/*
int main()
{
	char a = -128;
	// 11111111111111111111111110000000
	printf("%u\n", a);
	return 0;
}
*/


/*
int main()
{
	int** arr= (int**)malloc(3 * sizeof(int));
	if (arr == NULL)
	{
		perror("malloc");
		return 1;
	}
	arr[0] = (int*)malloc(5 * sizeof(int));
	arr[1] = (int*)malloc(5 * sizeof(int));
	arr[2] = (int*)malloc(5 * sizeof(int));
	if (arr[0] == NULL || arr[1] == NULL || arr[2] == NULL)
	{
		perror("malloc");
		return 1;
	}
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 5; j++)
		{
			arr[i][j] = j;
		}
	}
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 5; j++)
		{
			printf("%d ", arr[i][j]);
		}
	}
	free(arr[0]);
	arr[0] = NULL;
	free(arr[1]); 
	arr[1] = NULL;
	free(arr[2]);
	arr[2] = NULL;
	free(arr);
	arr = NULL;
	return 0;
}
*/


/*
int main()
{
	int* p = (int*)malloc(10 * sizeof(int));
	if (p == NULL)
	{
		perror("malloc");
		return 1;
	}
	for (int i = 0; i < 10; i++)
	{
		*(p + i) = i;
	}
	for (int i = 0; i < 10; i++)
	{
		printf("%d ", p[i]);
	}
	free(p);
	p = NULL;
	return 0;
}
*/



int main()
{
	int* p = (int*)calloc(10, sizeof(int));
	if (p == NULL)
	{
		perror("malloc");
		return 1;
	}
	for (int i = 0; i < 10; i++)
	{
		*(p + i) = i;
	}
	int* ptr = (int*)realloc(p, 5 * sizeof(int));
	if (ptr == NULL)
	{
		perror("realloc");
		return 1;
	}
	else
	{
		p = ptr;
		ptr = NULL;
	}
	/*for (int i = 10; i < 20; i++)
	{
		*(p + i) = i;
	}*/
	for (int i = 0; i < 5; i++)
	{
		printf("%d ", p[i]);
	}
	int a = 10;
	int* prr = &a;
	free(prr);
	free(p);
	p = NULL;
	return 0;
}

